<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>

<!--          <a-col :xs="24" :sm="12">
            <a-form-item label="订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['orderNo']" placeholder="请输入订单号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="产品" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['variety']" placeholder="请输入产品"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['varietyCode']" placeholder="请输入产品编码"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['packingSpecifications']" placeholder="请输入规格"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['flowerPoleLength']" placeholder="请输入单位"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="等级" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['classes']" placeholder="请输入等级"></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="出库数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['number']" placeholder="请输入出库数量"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="出库时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择出库时间" v-decorator="['stockInTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="出库人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['stockOutUser']" placeholder="请输入出库人"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">
            <a-form-item label="出库人id" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['stockOutUserid']" placeholder="请输入出库人id"></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="车牌" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['carNo']" placeholder="请输入车牌"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="司机" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['carDerver']" placeholder="请输入司机"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="司机电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['carPhone']" placeholder="请输入司机电话"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">
            <a-form-item label="渠道类型（先款后货，先货后款）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['type']" placeholder="请输入渠道类型（先款后货，先货后款）"></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['remarks']" placeholder="请输入备注"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">
            <a-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择创建日期" v-decorator="['createTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择更新日期" v-decorator="['updateTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['createUser']" placeholder="请输入创建人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['updateUser']" placeholder="请输入更新人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="状态（-1待出库，0已出库，1删除，2撤销）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['state']" placeholder="请输入状态（-1待出库，0已出库，1删除，2撤销）" style="width: 100%"/>
            </a-form-item>
          </a-col>-->

        </a-row>
      </a-form>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="出库单子表" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="flowerOutorderinfoTable.loading"
            :columns="flowerOutorderinfoTable.columns"
            :dataSource="flowerOutorderinfoTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </a-tab-pane>

      </a-tabs>

    </a-spin>
  </j-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: 'FlowerOutorderModal',
    mixins: [JEditableTableMixin],
    components: {
      JDate,
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
        },
        refKeys: ['flowerOutorderinfo', ],
        tableKeys:['flowerOutorderinfo', ],
        activeKey: 'flowerOutorderinfo',
        // 出库单子表
        flowerOutorderinfoTable: {
          loading: false,
          dataSource: [],
          columns: [
            /*{
              title: '订单id',
              key: 'orderId',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },*/
            {
              title: '产品',
              key: 'variety',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '产品编码',
              key: 'varietyCode',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '规格',
              key: 'packingSpecifications',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '单位',
              key: 'flowerPoleLength',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '等级',
              key: 'classes',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '数量',
              key: 'number',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            /*{
              title: '创建日期',
              key: 'createTime',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '更新日期',
              key: 'updateTime',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '创建人',
              key: 'createUser',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '更新人',
              key: 'updateUser',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '状态（0已出库，1删除，2撤销）',
              key: 'state',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },*/
          ]
        },
        url: {
          add: "/flower/flowerOutorder/add",
          edit: "/flower/flowerOutorder/edit",
          flowerOutorderinfo: {
            list: '/flower/flowerOutorder/queryFlowerOutorderinfoByMainId'
          },
        }
      }
    },
    methods: {
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'orderNo','variety','varietyCode','packingSpecifications','flowerPoleLength','classes','number','stockInTime','stockOutUser','stockOutUserid','carNo','carDerver','carPhone','type','remarks','createTime','updateTime','createUser','updateUser','state')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.flowerOutorderinfo.list, params, this.flowerOutorderinfoTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          flowerOutorderinfoList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row,'orderNo','variety','varietyCode','packingSpecifications','flowerPoleLength','classes','number','stockInTime','stockOutUser','stockOutUserid','carNo','carDerver','carPhone','type','remarks','createTime','updateTime','createUser','updateUser','state'))
     },

    }
  }
</script>

<style scoped>
</style>